#include<iostream>
#include<string> 
using namespace std;
class Date
{
public:
	Date(int year=1900,int month=1,int day=1)
	:_year(year)
	,_month(month)
	,_day(day)
	{} 
	static int GetDay(int year,int month)
	{
		static int day[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
		if(month==2 &&((year/4 ==0)&&(year/100!=100)||(year/400==0)))
		{
			return 29;
		}
			return day[month];
	}
	bool operator<(Date& d)
	{
		if(_year<d._year)
		{
			return true;
		}
		else if(_year==d._year && _month < d._month)
		{
			return true;
		}
		else if(_year==d._year && _month == d._month && _day < d._day)
		{
			return true;
		}
		return false;
	}
	Date& operator++()
	{
		_day+=1;
		if(_day>GetDay(_year,_month))
		{
			_day=1;
			_month+=1;
			if(_month == 12)
			{
				_year+=1;
				_month=1;	
			} 
		}
	}
	int compare()
	{
		int year = _year/1000+_year/100%10+_year/10%10+_year%10;
		int mday = _month/10+_month%10+_day/10+_day%10;
		if(year == mday)
		{
			count++;
		}
	}
	static int GetCount()
	{
		return count;
	}
private:
	int _year;
	int _month;
	int _day;
	static int count;
}; 
int Date::count = 0;
int main()
{
	Date d1;
	Date d2(9999,12,31);
	while(d1<d2)
	{
		d1.compare();
		++d1;
	}
	cout << Date::GetCount()<<endl;
	return 0;
}
